package com.server.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.server.common.base.ProjectInfor;
import com.server.service.IForeignStudyService;
import com.server.web.DataVector;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;
import com.server.web.RequestInput;

@Controller()
@RequestMapping("foreign/study")
public class ForeignStudyController {
	
	@Autowired
	private IForeignStudyService foreignStudyService;
	
	@RequestMapping("")
	public ModelAndView foreign(HttpServletRequest request,
			HttpServletResponse response){
		ModelAndView mv = new ModelAndView("study/foreign/foreignPage");
		mv.addObject("rootPath", ProjectInfor.ROOT_PATH);
		return mv;
	}
	@RequestMapping("list/{type}")
	public void list(HttpServletRequest request,
			HttpServletResponse response,@PathVariable Integer type){
		String whereStr = "state=5";
		String sortStr = "auditTime desc";
		DataVector<Map<String, Object>> listData = foreignStudyService.getList(type,whereStr, sortStr, new RequestInput(request));
		List<Map<String, Object>> list = listData.getList();
		OutputUtil.returnGridData(response, listData.getCount(), JSONSerielizer.toJson(list, null, null));
	}
	@RequestMapping("detail/{type}/{id}")
	public ModelAndView detail(HttpServletRequest request,HttpServletResponse response
			,@PathVariable Integer type,@PathVariable Integer id){
		Map<String, Object> fMap = foreignStudyService.foreignDetail(id, type);
		ModelAndView mv = new ModelAndView("study/foreign/foreignPage_details");
		mv.addObject("type", type);
		mv.addObject("fMap", fMap);
		return mv;
	}
}
